/**
 * 防抖, 时间触发n秒后执行, 如果n秒前再次触发, 则重新计时
 * 多次触发执行最后一次
 * **/

function debounce (fn, wait) {
  let timer
  return function (params) {
    const _this = this
    const args = arguments
    clearTimeout(timer)
    timer = setTimeout(function () {
      timer = null
      fn.apply(_this, args)
    }, wait)
  }
}

let fn = debounce((val) => { console.log(val); })
fn(1)
fn(12)
fn(13)
setTimeout(() => { fn(1333) }, 0)


function throttle (fn, wait) {
  let timer
  return function () {
    let _this = this
    let args = arguments
    if (!timer) {
      timer = setTimeout(function () {
        // clearTimeout(timer)
        timer = null
        fn.apply(_this, args)
      }, wait)
    }
  }
}

let fn2 = throttle(val => { console.log(val); }, 100)
fn2(1)
fn2(2)
fn2(3)
setTimeout(() => { fn2(333) }, 100)


let a = [3, 1, 3, 4, 5, 6, 7]
var containsDuplicate = function (nums) {
  nums.sort()
  console.log(nums);
  for (const key in nums) {
    if (nums[key] === nums[key + 1]) {
      return true
    }
    return false
  }
};

containsDuplicate(a)